package com.zyw.security.shiro.web.authc;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户认证信息
 *
 * @author zhangyw
 * @date 2018/1/11 16:01
 */
public class AuthInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer userid;
    private String username;
    private String password; // 非必须
    private Integer status; // 状态 0 正常 ， 1 停用

    private boolean anon = false; // 是否匿名访问 主要针对小程序或者其它第三方账户，第一次访问时无关联账户使用
    private String authType; // 认证类型 参考loginFrom

    private Map<String, Object> attributes;

    public Integer getUserid() {
        return userid;
    }

    public void setUserid(Integer userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public boolean isAnon() {
        return anon;
    }

    public void setAnon(boolean anon) {
        this.anon = anon;
    }

    /**
     * @see com.zyw.security.shiro.LoginFrom
     * @return loginFrom
     */
    public String getAuthType() {
        return authType;
    }

    public void setAuthType(String authType) {
        this.authType = authType;
    }

    public Map<String, Object> getAttributes() {
        return attributes;
    }

    public void setAttributes(Map<String, Object> attributes) {
        this.attributes = attributes;
    }

    public void addAttribute(String key, Object value) {
        if (this.attributes == null) {
            this.attributes = new HashMap<>();
        }
        this.attributes.put(key, value);
    }

    public Object getAttribute(String key) {
        return attributes == null ? null : attributes.get(key);
    }

    public void addAllAttributes(Map<String, Object> attributes) {
        if (this.attributes == null) {
            this.attributes = new HashMap<>();
        }
        this.attributes.putAll(attributes);
    }
}
